<template>
	<view class="body">
		<xk-header title="日常工作登记"></xk-header>

		<view v-if="data.status == '40'" class="list">
			<view class="list-item header" @click="orderMore = !orderMore">
				<view>抽查记录: </view>
				<image v-if="!orderMore" src="/static/up.png"></image>
				<image v-else src="/static/down.png"></image>
			</view>
			<view v-if="orderMore" class="data-item">
				<view class="order-info">
					<view class="info-item">
						<view class="key">抽查结果：</view>不通过
					</view>
					<view class="info-item">
						<view class="key">抽查意见：</view>{{ data.check_remark }}
					</view>
				</view>
			</view>
		</view>

		<view class="list">
			<view>
				<picker :range="kwType" :value="kwIndex" range-key="data_text" @change="kwTypeChange">
					<view class="list-item">
						<view>工作类型<text class="com-req"></text>:</view>
						<view :class="formInfo.kw_type !== '' ? 'right-title1' : 'right-title1 right-title1-empty'">
							{{ formInfo.kw_type !== '' ? kwTypeMap[formInfo.kw_type] : "请选择" }}</view>
						<image mode="aspectFill" class="jiantou" src="/static/jiantou.png" />
					</view>
				</picker>
				<!-- <picker :range="whether" :value="is_record" range-key="data_text" @change="PicChange">
					<view class="list-item">
						<view>是否重点事项<text class="com-req"></text>:</view>
						<view :class="formInfo.is_record !== '' ? 'right-title1' : 'right-title1 right-title1-empty'">
							{{ formInfo.is_record !== '' ? whether[formInfo.is_record] : "请选择" }}</view>
						<image mode="aspectFill" class="jiantou" src="/static/jiantou.png" />
					</view>
				</picker> -->
				<picker :value="is_record" mode="selector" :range="whether" @change="PicChange">
					<view class="list-item">
						<view>是否重点事项<text class="com-req"></text>:</view>
						<view :class="formInfo.is_record !== '' ? 'right-title1' : 'right-title1 right-title1-empty'">
							{{ formInfo.is_record !== '' ? whether[formInfo.is_record] : "请选择" }}</view>
						<image mode="aspectFill" class="jiantou" src="/static/jiantou.png" />
						<!-- {{ whether[formInfo.is_record] }} -->
					</view>
				</picker>
				<picker :range="urgency" :value="urgencyIndex" range-key="data_text" @change="urgencyChange">
					<view class="list-item">
						<view>重要程度<text class="com-req"></text>:</view>
						<view :class="formInfo.urgency !== '' ? 'right-title1' : 'right-title1 right-title1-empty'">
							{{ formInfo.urgency !== '' ? urgencyMap[formInfo.urgency] : "请选择" }}</view>
						<image mode="aspectFill" class="jiantou" src="/static/jiantou.png" />
					</view>
				</picker>
				<picker mode="date" :value="formInfo.start_time" @change="dealStartTimeChange">
					<view class="list-item">
						<view>开始时间<text class="com-req"></text>：</view>
						<view :class="formInfo.start_time ? 'right-title1' : 'right-title1 right-title1-empty'">
							{{ formInfo.start_time ? formInfo.start_time : "请选择" }}</view>
						<image mode="aspectFill" class="jiantou" src="/static/jiantou.png" />
					</view>
				</picker>
				<picker mode="date" :value="formInfo.end_time" @change="dealEndTimeChange">
					<view class="list-item">
						<view>结束时间<text class="com-req"></text>：</view>
						<view :class="formInfo.end_time ? 'right-title1' : 'right-title1 right-title1-empty'">
							{{ formInfo.end_time ? formInfo.end_time : "请选择" }}</view>
						<image mode="aspectFill" class="jiantou" src="/static/jiantou.png" />
					</view>
				</picker>
				<!-- <biaofun-datetime-picker :defaultValue="defaultDate"
					start="2000-02-03 00:00"
					end="2200-10-28 23:59"
					fields="minute"
					@change="dealStartTimeChange"
				>
					<view class="list-item">
						<view>开始时间<text class="com-req"></text>：</view>
						<view :class="formInfo.start_time ? 'right-title1' : 'right-title1 right-title1-empty'">{{formInfo.start_time ? formInfo.start_time : "请选择"}}</view>
						<image mode="aspectFill" class="jiantou" src="/static/jiantou.png"/>
					</view>
				</biaofun-datetime-picker>
				<biaofun-datetime-picker :defaultValue="defaultDate"
					start="2000-02-03 00:00"
					end="2200-10-28 23:59"
					fields="minute"
					@change="dealEndTimeChange"
				>
					<view class="list-item">
						<view>结束时间<text class="com-req"></text>：</view>
						<view :class="formInfo.end_time ? 'right-title1' : 'right-title1 right-title1-empty'">{{formInfo.end_time ? formInfo.end_time : "请选择"}}</view>
						<image mode="aspectFill" class="jiantou" src="/static/jiantou.png"/>
					</view>
				</biaofun-datetime-picker> -->
				<view class="list-item textarea">
					<view>工作内容<text class="com-req"></text>：</view>
					<textarea v-model="formInfo.kw_content" placeholder="在此输入工作内容" placeholder-class="placeholder" />
				</view>
				<view class="list-item textarea">
					<view>备注：</view>
					<textarea v-model="formInfo.record_remark" placeholder="在此输入备注" placeholder-class="placeholder" />
				</view>
			</view>
		</view>
		<view class="from-item upload-img-item" style="margin-top: 20rpx;">
			<view class="title">上传工作图片</view>
			<upload-image :images="formInfo.image" @onChange="(images) => { formInfo.image = images }" />
		</view>
		<!-- <view class="upload-img-item">
			<view class="title">上传巡查照片</view>
			<upload-image images="" @onChange="uploadImageChange"/>
		</view> -->
		<view class="common-bottom-view">
			<!-- <view class="common-btn btn-plant" @click="doneRepair">保存</view> -->
			<view class="common-btn" @click="submitRecord">提交</view>
		</view>
		<view class="common-zw"></view>


	</view>
</template>

<script>
import moment from 'moment'
export default {
	data() {
		return {
			orderMore: true,
			data: {},
			is_record: 0,
			defaultDate: moment().format('YYYY-MM-DD HH:mm'),
			kwType: [],
			kwIndex: '',
			kwTypeMap: {},
			urgency: [],
			urgencyMap: {},
			urgencyIndex: 0,
			whether: ['否', '是'],
			formInfo: {
				kword_id: '',
				start_time: '',
				end_time: '',
				kw_type: '',
				urgency: '',
				is_record: '',
				kw_content: '',
				image: '',
				record_remark: '',
				isSubmit: true
			},
			notNull: {
				kw_type: '工作类型不能为空',
				urgency: '重要程度不能为空',
				is_record: '是否重点事项不能为空',
				kw_content: "工作内容不能为空",
				start_time: '开始时间不能为空',
				end_time: '结束时间不能为空'
			}
		};
	},
	onLoad(options) {
		this.initInfo()
		if (options.kwordId) {
			this.formInfo.kword_id = options.kwordId;
			this.getData()
		}
	},
	onUnload() {
	},
	methods: {
		PicChange(e) {
			console.log('eeeeee', e)
			this.formInfo.is_record = e.detail.value
			this.is_record = e.detail.value
			console.log('this.formInfo.is_record', this.formInfo.is_record)
		},
		dealStartTimeChange(e) {
			// this.formInfo.start_time = moment(e.dt).format('YYYY-MM-DD HH:mm')
			this.formInfo.start_time = e.detail.value
		},
		dealEndTimeChange(e) {
			// this.formInfo.end_time = moment(e.dt).format('YYYY-MM-DD HH:mm')
			this.formInfo.end_time = e.detail.value
		},
		kwTypeChange(e) {
			this.kwIndex = e.detail.value;
			this.formInfo.kw_type = this.kwType[this.kwIndex].data_value
		},
		urgencyChange(e) {
			this.urgencyIndex = e.detail.value;
			this.formInfo.urgency = this.urgency[this.urgencyIndex].data_value
		},
		getData() {
			this.$api.baseData_getPmKword(this.formInfo.kword_id).then((res) => {
				this.data = res.task
				this.formInfo = Object.assign(this.formInfo, res.task)
			})
		},
		initInfo() {
			this.$api.baseData_getToolDataList({
				code: "PM_KWORD_KW_TYPE" + "_nostr"
			}).then(res => {
				this.kwType = res
				let kwTypeMap = {}
				for (let item of res) {
					kwTypeMap[item.data_value] = item.data_text
				}
				this.kwTypeMap = kwTypeMap
			})
			this.$api.baseData_getToolDataList({
				code: "PM_KWORD_URGENCY" + "_nostr"
			}).then(res => {
				this.urgency = res
				let urgencyMap = {}
				for (let item of res) {
					urgencyMap[item.data_value] = item.data_text
				}
				this.urgencyMap = urgencyMap
			})
		},
		submitRecord() {
			console.warn("formInfo: ", this.formInfo)
			for (let item in this.notNull) {
				if (this.formInfo[item] === '' || this.formInfo[item] === null || this.formInfo[item] === undefined) {
					this.$util.toast(this.notNull[item]);
					return;
				}
			}
			this.$util.confirm({
				content: "确定提交日常工作记录？",
				confirmText: "确定"
			}).then(isConfirm => {
				if (isConfirm) {
					this.$util.post({
						url: "app/pmKword/createUpdatePmKword",
						data: {
							kword_id: this.formInfo.kword_id,
							start_time: this.formInfo.start_time,
							end_time: this.formInfo.end_time,
							kw_type: this.formInfo.kw_type,
							urgency: this.formInfo.urgency,
							is_record: this.formInfo.is_record,
							kw_content: this.formInfo.kw_content,
							image: this.formInfo.image,
							record_remark: this.formInfo.record_remark,
							isSubmit: true
						}
					}).then(res => {
						// uni.$emit('refreshHomeDataList')
						uni.$emit('refreshDailyWork')
						uni.redirectTo({
							url: '/pagesA/daily-work/daily-work-finish?type=done'
						})
					})

				}
			})

		}
	}
}
</script>

<style lang="scss" scoped>
@import '@/common/from.scss';
</style>
